package cn.classTest.mall.controller;

import cn.classTest.mall.domain.Goods;
import cn.classTest.mall.domain.Warehouse;
import cn.classTest.mall.query.QueryObject;
import cn.classTest.mall.service.GoodsService;
import cn.classTest.mall.service.WarehouseService;
import com.github.pagehelper.PageInfo;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
@RequestMapping("/warehouse")
public class WarehouseController {

    @Autowired
    private WarehouseService warehouseService;

    @Autowired
    private GoodsService goodsService;

    /*
     * DepartmentController:list
     * */
    @RequiresPermissions(value = {"warehouse:list", "库存列表"}, logical = Logical.OR)
    @RequestMapping("/list")
    public String list(Model model, QueryObject qo) {
        PageInfo<Warehouse> query = warehouseService.query(qo);
        model.addAttribute("pageInfo", query);
        List<Goods> goodsList = goodsService.selectAll();
        model.addAttribute("goodsList", goodsList);
        return "warehouse/list";
    }


    @RequiresPermissions(value = {"warehouse:input", "库存编辑"}, logical = Logical.OR)
    @RequestMapping("/input")
    public String input(Model model, Long id) {
        List<Goods> goodsList = goodsService.selectAll();

        model.addAttribute("goodsList", goodsList);
        if (id != null) {
            Warehouse warehouse = warehouseService.selectOne(id);
            System.out.println(warehouse);
            model.addAttribute("warehouse", warehouse);
        }
        return "/warehouse/input";
    }






}
